package com.three.lab.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.three.lab.R;

import java.util.List;

public class StackedAvatarAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    public StackedAvatarAdapter(@Nullable List<String> data) {
        super(R.layout.item_list_avatar, data);
    }

    public StackedAvatarAdapter() {
        super(R.layout.item_list_avatar);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, String item) {
        int position = helper.getLayoutPosition();
        //为0是不折叠（核心）
        if(position==0){
            setMargins(helper.itemView,0,0,0,0);
        }
        ImageView imageView = helper.getView(R.id.iv_avatar);
        Glide.with(mContext).load(item).placeholder(R.mipmap.ic_avatar_52).diskCacheStrategy(DiskCacheStrategy.ALL).skipMemoryCache(false).into(imageView);
//        if (helper.getLayoutPosition() == 0) {
//            setMargins(helper.getConvertView(),0,0,0,0);
//        }
    }

    private void setMargins(View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }
}
